import 'package:flutter/material.dart';
import 'package:flutter_easyrefresh/easy_refresh.dart';
import 'package:flutterhello/api/api.dart';
import 'package:flutterhello/pages/two/widget/inviteCard.dart';
import 'package:flutterhello/widgets/loading_dialog.dart';

class Invite extends StatefulWidget {
  @override
  _InviteState createState() => _InviteState();
}

class _InviteState extends State<Invite> {
  var page = 1;
  var pageSize = 20;
  var list = [];

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  void refresh() async {
    this.page = 1;
    this.pageSize = 20;
    var res = await Api.getRecruit({"page": page, "pageSize": pageSize});
    this.list = res['data']['recruid_list'];
    setState(() {});
  }

  @override
  Widget build(BuildContext context) {
    return EasyRefresh.custom(
      firstRefresh: true,
      firstRefreshWidget: Container(
        width: double.infinity,
        height: double.infinity,
        color: Colors.white,
        child: Center(
          child: CircularProgressIndicator(),
        ),
      ),
      header: MaterialHeader(),
      footer: MaterialFooter(),
      onRefresh: () async {
        await this.refresh();
      },
      slivers: <Widget>[
        SliverToBoxAdapter(
          child: Padding(
            padding: EdgeInsets.only(left: 20, right: 20, top: 10, bottom: 10),
            child: Container(
              width: double.infinity,
              height: 160,
              child: ClipRRect(
                borderRadius: BorderRadius.all(Radius.circular(10)),
                child: Image.network(
                  'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201808%2F15%2F20180815093329_ilxkw.jpg&refer=http%3A%2F%2Fb-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1623327459&t=c8f35d37bb7d608c481ae700a41d143a',
                  fit: BoxFit.cover,
                ),
              ),
            ),
          ),
        ),
        SliverList(
          delegate: SliverChildBuilderDelegate(
            (BuildContext context, int index) {
              return Padding(
                padding: EdgeInsets.only(left: 5, right: 5),
                child: InviteCard(
                  info: this.list[list.length - index - 1],
                ),
              );
            },
            childCount: list.length,
          ),
        )
      ],
    );
  }
}
